﻿namespace xrwang.DDNS.DNSExit
{
    /// <summary>
    /// 服务器响应
    /// </summary>
    /// <see cref="https://dnsexit.com/dns/dns-api/"/>
    public class ServerReply
    {
        /// <summary>
        /// 成功的响应代码
        /// </summary>
        public const int SUCCESS_CODE = 0;
        /// <summary>
        /// 异常的响应代码
        /// </summary>
        public const int EXCEPTION_CODE = -999;

        /// <summary>
        /// 响应代码
        /// </summary>
        public int code { get; set; }
        /// <summary>
        /// 详细情况
        /// </summary>
        public string[] details { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string message { get; set; }

        /// <summary>
        /// 获取是否成功
        /// </summary>
        public bool Success
        {
            get
            {
                return code == SUCCESS_CODE;
            }
        }

        /// <summary>
        /// 返回字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("是否成功：{1}{0}响应代码：{2}{0}消息：{3}{0}详细情况：{4}",
                Environment.NewLine, Success, code, message,
                details != null ? string.Join<string>(Environment.NewLine, details) : string.Empty);
        }
    }
}